<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="井内钻井液密度 (kg/m³)" prop="jnzjy">
				<u-input :border="border" placeholder="井内钻井液密度 (kg/m³)" v-model="model.jnzjy" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="井深 (m)" prop="jingshen">
				<u-input :border="border" placeholder="井深 " v-model="model.jingshen" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="关井立管压力 (MPa)" prop="gjxgyl">
				<u-input :border="border" placeholder="关井立管压力 " v-model="model.gjxgyl" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}"
					label-width="300" :label-position="labelPosition" label="地层压力的值为：" prop="diFaLan">
					<span v-if="model.dcyl"> {{model.dcyl}} MPa </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">Pl=10^-3ρgH+Pm</view>
				<view class="u-item-desc">式中：<br>
					Pl —井底地层压力，MPa；<br>
					ρ—井内钻井液密度，kg/m³；<br>
					g—9.81，m/s²；<br>
					H—井深，m；<br>
					Pm—关井立管压力，MPa。</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					jnzjy: '',
					jingshen: '',
					gjxgyl: '',
					dcyl: ''
				},
				rules: {
					jnzjy: [{
						required: true,
						message: '请填写井内钻井液密度',
						trigger: 'blur'
					}],
					jingshen: [{
						required: true,
						message: '请填写井深',
						trigger: 'blur'
					}],
					gjxgyl: [{
						required: true,
						message: '请填写关井立管压力',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,

			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
							
							const ρ = parseFloat(this.model.jnzjy);
							const H = parseFloat(this.model.jingshen);
							const g = 9.81; // 重力加速度，m/s²
							const ph=parseFloat(this.model.gjxgyl);
							
							
							// Pl = 10⁻³ × ρ × g × H + Pm
							this.model.dcyl = (0.001 * ρ * g * H +ph).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>